<template>
  <div>
    <div>
      <el-button type="primary" @click="toadd">添加</el-button>
    </div>
    <!-- 表 -->
    <el-table :data="logLists" style="width: 100%">
      <el-table-column prop="id" label="id" width="180">
      </el-table-column>
      <el-table-column prop="realname" label="姓名" width="180">
      </el-table-column>
      <el-table-column prop="method" label="方法">
      </el-table-column>
      <el-table-column prop="content" label="内容">
      </el-table-column>
      <el-table-column prop="logTime" label="发布时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="180">
        <template v-slot="scope">
          <div>
            <el-tag style="cursor: pointer;" @click="toedit(scope.row)">修改</el-tag>
            <!-- {{ scope.row }} -->
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 模太狂 -->
    <div>
      <el-dialog :title=title :visible.sync="dialogVisible" width="30%">
        <el-form :model="form" label-width="80px">
          <el-form-item label="姓名">
            <el-input v-model="form.realname"></el-input>
          </el-form-item>
          <el-form-item label="方法">
            <el-input v-model="form.method"></el-input>
          </el-form-item>
          <el-form-item label="内容">
            <el-input v-model="form.content"></el-input>
          </el-form-item>
        </el-form>
        <div style="text-align: center;">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="tosave()">确 定</el-button>
        </div>
      </el-dialog>
    </div>
    <div class="page" style="text-align: center;">
      <el-pagination :current-page="params.page" :page-sizes="[5, 10, 15, 20]" :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
        @current-change="handleCurrentChange" />
    </div>
  </div>
</template>
<script>
import { get, post } from '@/utils/request';
export default {
  data() {
    return {
      logLists: [],
      params: {
        page: 1,
        pageSize: 20
      },
      dialogVisible: false,
      form: {},
      title: '新增日志内容',
      total:0
    }
  },
  methods: {
    // 当前页码条数发生改变触发
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.pageSize = val
      this.params.page = 1
      this.getArticle()
    },
    // 当前页码发生改变触发的方法
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.page = val
      this.getArticle()
    },
    async toedit(row) {
      this.dialogVisible = true;
      this.title = '修改日志内容';
      this.form = { ...row };
    },
    async tosave() {
      this.dialogVisible = false;
      const res = await post('/baseLog/save', this.form)
      this.getLog();
    },
    toadd() {
      this.dialogVisible = true;
    },
    async getLog() {
      const res = await get('/baseLog/pageQuery', this.params)
      this.logLists = res.data.list;
      this.total = res.data.list.total;
    }
  },
  created() {
    this.getLog();
  }
}
</script>